/*
 * EBAansluitingen.java
 *
 * Created on 19 mei 2008, 19:56
 */

package energiebedrijf;

import energiebedrijf.Classes.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;

/**
 * Formulier om aansluitingen mee te editen
 * @author  pdb
 */
public class EBAansluitingen extends javax.swing.JDialog {
    
    private Perceel Perceel;
    private Boolean _cancelled;

    /** Creates new form EBAansluitingen */
    public EBAansluitingen(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        
        this.setLocationRelativeTo(parent);
    }
    
    /** Deze constructor maakt een nieuw formulier aan en laat de gegevens van 
     * het doorgegeven Perceel object zien
     * @param perceel Het Perceel object wat ge-edit moet worden
     */
    public EBAansluitingen(java.awt.Frame parent, boolean modal,Perceel perceel) {
        this(parent, modal);
        this.Perceel = perceel;
        
        if (this.Perceel.getPerceelId() == -1) {
            //Nieuw perceel
            chkGasaansluiting.setEnabled(false);
            jdIngangsdatumGas.setEnabled(false);
            chkElectraAansluiting.setEnabled(false);
            jdIngangsdatumElectra.setEnabled(false);
            chkWaterAansluiting.setEnabled(false);
            jdIngangsdatumWater.setEnabled(false);
            this.setTitle("Nieuw perceel invoeren");
        } else {
            txtStraatnaam.setText(perceel.getStraatnaam());
            txtHuisnummer.setText(perceel.getHuisnummer());
            txtPostcode.setText(perceel.getPostcode());
            txtPlaats.setText(perceel.getPlaats());

            if (perceel.getGas() == null) {
                chkGasaansluiting.setSelected(false);
            } else {
                chkGasaansluiting.setSelected(true);
                jdIngangsdatumGas.setDate(Perceel.getGas().getIngangsdatum());
                txtGasVerbruik.setText(Integer.toString(Perceel.getGas().getVerbruik()));
                txtGasVorigeMeterstand.setText(Integer.toString(Perceel.getGas().getVorigeMeterstand()));

            }

            if (this.Perceel.getElectriciteit() == null) {
                chkElectraAansluiting.setSelected(false);
            } else {
                chkElectraAansluiting.setSelected(true);
                jdIngangsdatumElectra.setDate(Perceel.getElectriciteit().getIngangsdatum());
                txtElectraVerbruik.setText(Integer.toString(Perceel.getElectriciteit().getVerbruik()));
                txtElectraVerbruikNacht.setText(Integer.toString(Perceel.getElectriciteit().getVerbruikNacht()));
                txtElectraVorigeMeterstand.setText(Integer.toString(Perceel.getElectriciteit().getVorigeMeterstand()));
            }

            if (this.Perceel.getWater() == null) {
                chkWaterAansluiting.setSelected(false);
            } else {
                chkWaterAansluiting.setSelected(true);
                jdIngangsdatumWater.setDate(Perceel.getWater().getIngangsdatum());
                jTextField2.setText(Integer.toString(Perceel.getWater().getVerbruik()));
                jTextField3.setText(Integer.toString(Perceel.getWater().getVorigeMeterstand()));
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtStraatnaam = new javax.swing.JTextField();
        txtHuisnummer = new javax.swing.JTextField();
        txtPostcode = new javax.swing.JTextField();
        txtPlaats = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        pnlGasAansluiting = new javax.swing.JPanel();
        chkGasaansluiting = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtGasVerbruik = new javax.swing.JTextField();
        txtGasVorigeMeterstand = new javax.swing.JTextField();
        jdIngangsdatumGas = new com.toedter.calendar.JDateChooser();
        pnlWaterAansluiting = new javax.swing.JPanel();
        chkWaterAansluiting = new javax.swing.JCheckBox();
        jLabel10 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jdIngangsdatumWater = new com.toedter.calendar.JDateChooser();
        pnlElectraAansluiting = new javax.swing.JPanel();
        chkElectraAansluiting = new javax.swing.JCheckBox();
        txtElectraVerbruik = new javax.swing.JTextField();
        txtElectraVerbruikNacht = new javax.swing.JTextField();
        txtElectraVorigeMeterstand = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jdIngangsdatumElectra = new com.toedter.calendar.JDateChooser();
        btnAnnuleren = new javax.swing.JButton();
        btnOpslaan = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(energiebedrijf.EnergieBedrijfApp.class).getContext().getResourceMap(EBAansluitingen.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel3.setName("jPanel3"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jTextField1.setText(resourceMap.getString("txtStraatnaam.text")); // NOI18N
        jTextField1.setName("txtStraatnaam"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        txtStraatnaam.setText(resourceMap.getString("txtStraatnaam.text")); // NOI18N
        txtStraatnaam.setName("txtStraatnaam"); // NOI18N

        txtHuisnummer.setText(resourceMap.getString("txtHuisnummer.text")); // NOI18N
        txtHuisnummer.setName("txtHuisnummer"); // NOI18N

        txtPostcode.setText(resourceMap.getString("txtPostcode.text")); // NOI18N
        txtPostcode.setName("txtPostcode"); // NOI18N

        txtPlaats.setText(resourceMap.getString("txtPlaats.text")); // NOI18N
        txtPlaats.setName("txtPlaats"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel8)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtStraatnaam, javax.swing.GroupLayout.DEFAULT_SIZE, 916, Short.MAX_VALUE)
                    .addComponent(txtPostcode, javax.swing.GroupLayout.DEFAULT_SIZE, 916, Short.MAX_VALUE)
                    .addComponent(txtPlaats, javax.swing.GroupLayout.DEFAULT_SIZE, 916, Short.MAX_VALUE)
                    .addComponent(txtHuisnummer, javax.swing.GroupLayout.DEFAULT_SIZE, 916, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtStraatnaam))
                .addGap(8, 8, 8)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtHuisnummer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtPostcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtPlaats, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new java.awt.GridLayout(1, 3, 2, 2));

        pnlGasAansluiting.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlGasAansluiting.setName("pnlGasAansluiting"); // NOI18N

        chkGasaansluiting.setText(resourceMap.getString("chkGasaansluiting.text")); // NOI18N
        chkGasaansluiting.setName("chkGasaansluiting"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        txtGasVerbruik.setEditable(false);
        txtGasVerbruik.setText(resourceMap.getString("txtGasVerbruik.text")); // NOI18N
        txtGasVerbruik.setName("txtGasVerbruik"); // NOI18N

        txtGasVorigeMeterstand.setEditable(false);
        txtGasVorigeMeterstand.setText(resourceMap.getString("txtGasVorigeStand.text")); // NOI18N
        txtGasVorigeMeterstand.setName("txtGasVorigeStand"); // NOI18N

        jdIngangsdatumGas.setName("jdIngangsdatumGas"); // NOI18N

        javax.swing.GroupLayout pnlGasAansluitingLayout = new javax.swing.GroupLayout(pnlGasAansluiting);
        pnlGasAansluiting.setLayout(pnlGasAansluitingLayout);
        pnlGasAansluitingLayout.setHorizontalGroup(
            pnlGasAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlGasAansluitingLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlGasAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlGasAansluitingLayout.createSequentialGroup()
                        .addGroup(pnlGasAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlGasAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(chkGasaansluiting))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlGasAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtGasVorigeMeterstand)
                    .addComponent(jdIngangsdatumGas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtGasVerbruik, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE))
                .addContainerGap())
        );
        pnlGasAansluitingLayout.setVerticalGroup(
            pnlGasAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlGasAansluitingLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(pnlGasAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlGasAansluitingLayout.createSequentialGroup()
                        .addComponent(chkGasaansluiting)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5))
                    .addComponent(jdIngangsdatumGas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlGasAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtGasVerbruik, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlGasAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtGasVorigeMeterstand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.add(pnlGasAansluiting);

        pnlWaterAansluiting.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlWaterAansluiting.setName("pnlWaterAansluiting"); // NOI18N

        chkWaterAansluiting.setText(resourceMap.getString("chkWaterAansluiting.text")); // NOI18N
        chkWaterAansluiting.setName("chkWaterAansluiting"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jTextField2.setEditable(false);
        jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N
        jTextField2.setName("jTextField2"); // NOI18N

        jTextField3.setEditable(false);
        jTextField3.setText(resourceMap.getString("jTextField3.text")); // NOI18N
        jTextField3.setName("jTextField3"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jdIngangsdatumWater.setName("jdIngangsdatumWater"); // NOI18N

        javax.swing.GroupLayout pnlWaterAansluitingLayout = new javax.swing.GroupLayout(pnlWaterAansluiting);
        pnlWaterAansluiting.setLayout(pnlWaterAansluitingLayout);
        pnlWaterAansluitingLayout.setHorizontalGroup(
            pnlWaterAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlWaterAansluitingLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlWaterAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(chkWaterAansluiting))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlWaterAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jdIngangsdatumWater, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextField3)
                    .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE))
                .addContainerGap(51, Short.MAX_VALUE))
        );
        pnlWaterAansluitingLayout.setVerticalGroup(
            pnlWaterAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlWaterAansluitingLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlWaterAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlWaterAansluitingLayout.createSequentialGroup()
                        .addComponent(chkWaterAansluiting)
                        .addGap(4, 4, 4)
                        .addComponent(jLabel10))
                    .addComponent(jdIngangsdatumWater, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlWaterAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlWaterAansluitingLayout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(pnlWaterAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlWaterAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel11)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(45, Short.MAX_VALUE))
        );

        jPanel1.add(pnlWaterAansluiting);

        pnlElectraAansluiting.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlElectraAansluiting.setName("pnlElectraAansluiting"); // NOI18N

        chkElectraAansluiting.setText(resourceMap.getString("chkElectraAansluiting.text")); // NOI18N
        chkElectraAansluiting.setName("chkElectraAansluiting"); // NOI18N

        txtElectraVerbruik.setEditable(false);
        txtElectraVerbruik.setText(resourceMap.getString("txtElectraVerbruik.text")); // NOI18N
        txtElectraVerbruik.setName("txtElectraVerbruik"); // NOI18N

        txtElectraVerbruikNacht.setEditable(false);
        txtElectraVerbruikNacht.setText(resourceMap.getString("txtElectraVerbruikNacht.text")); // NOI18N
        txtElectraVerbruikNacht.setName("txtElectraVerbruikNacht"); // NOI18N

        txtElectraVorigeMeterstand.setEditable(false);
        txtElectraVorigeMeterstand.setText(resourceMap.getString("txtElectraVorigeMeterstand.text")); // NOI18N
        txtElectraVorigeMeterstand.setName("txtElectraVorigeMeterstand"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jdIngangsdatumElectra.setName("jdIngangsdatumElectra"); // NOI18N

        javax.swing.GroupLayout pnlElectraAansluitingLayout = new javax.swing.GroupLayout(pnlElectraAansluiting);
        pnlElectraAansluiting.setLayout(pnlElectraAansluitingLayout);
        pnlElectraAansluitingLayout.setHorizontalGroup(
            pnlElectraAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlElectraAansluitingLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlElectraAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chkElectraAansluiting, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(pnlElectraAansluitingLayout.createSequentialGroup()
                        .addGroup(pnlElectraAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15)
                            .addComponent(jLabel9))
                        .addGroup(pnlElectraAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlElectraAansluitingLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(txtElectraVorigeMeterstand, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlElectraAansluitingLayout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addGroup(pnlElectraAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtElectraVerbruikNacht, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                                    .addComponent(txtElectraVerbruik, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                                    .addComponent(jdIngangsdatumElectra, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE))))
                        .addGap(63, 63, 63)))
                .addContainerGap())
        );
        pnlElectraAansluitingLayout.setVerticalGroup(
            pnlElectraAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlElectraAansluitingLayout.createSequentialGroup()
                .addComponent(chkElectraAansluiting)
                .addGap(5, 5, 5)
                .addGroup(pnlElectraAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel9)
                    .addComponent(jdIngangsdatumElectra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlElectraAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtElectraVerbruik, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlElectraAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(txtElectraVerbruikNacht, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlElectraAansluitingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtElectraVorigeMeterstand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jPanel1.add(pnlElectraAansluiting);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(energiebedrijf.EnergieBedrijfApp.class).getContext().getActionMap(EBAansluitingen.class, this);
        btnAnnuleren.setAction(actionMap.get("btnAnnuleren_Click")); // NOI18N
        btnAnnuleren.setText(resourceMap.getString("btnAnnuleren.text")); // NOI18N
        btnAnnuleren.setName("btnAnnuleren"); // NOI18N

        btnOpslaan.setAction(actionMap.get("btnOpslaan_Click")); // NOI18N
        btnOpslaan.setText(resourceMap.getString("btnOpslaan.text")); // NOI18N
        btnOpslaan.setName("btnOpslaan"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 1030, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnOpslaan)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnAnnuleren)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnAnnuleren, btnOpslaan});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAnnuleren)
                    .addComponent(btnOpslaan))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    // TODO Controleer of er wijzigingen zijn!:
    if (true) {
        //Geen wijzigingen sluit scherm
        this.setVisible(false);
    } else {
        //Vraag of er gesloten moet worden
    }

}//GEN-LAST:event_formWindowClosing

    /**
     * Annuleer de wijzigingen
     */
    @Action
    public void btnAnnuleren_Click() {
        //TODO: Bij wijzigingen bevestiging vragen
        if (JOptionPane.showConfirmDialog(this, "U hebt gegevens gewijzigd. Als u het scherm nu sluit\r\nverliest u deze wijzigingen. Weet u zeker dat u dat wilt?", "Bevestigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            this._cancelled = true;
            this.setVisible(false);
        }
    }

    /**
     * Sla de wijzigingen op
     * @throws java.text.ParseException
     */
    @Action
    public void btnOpslaan_Click() throws ParseException {
        //TODO: Bevestiging vragen
        if (JOptionPane.showConfirmDialog(this, "Weet u zeker dat u de wijzigingen wilt opslaan?", "Bevestigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            this._cancelled = false;
            this.getPerceel().setStraatnaam(txtStraatnaam.getText());
            this.getPerceel().setHuisnummer(txtHuisnummer.getText());
            this.getPerceel().setPostcode(txtPostcode.getText());
            this.getPerceel().setPlaats(txtPlaats.getText());

            //Save aansluitingen als het een bestaand perceel is.
            if (this.getPerceel().getPerceelId() != -1) {
                //Gas aansluiting
                if (this.getPerceel().getGas() == null && this.chkGasaansluiting.isSelected()) {
                    this.getPerceel().setGas(new Gas());
                    this.getPerceel().getGas().setPerceel(this.getPerceel());
                    this.getPerceel().getGas().setIngangsdatum(jdIngangsdatumGas.getDate());
                }
                //Electriciteits aansluiting
                if (this.getPerceel().getElectriciteit() == null && this.chkElectraAansluiting.isSelected()) {
                    this.getPerceel().setElectriciteit(new Electriciteit());
                    this.getPerceel().getElectriciteit().setPerceel(this.getPerceel());
                    this.getPerceel().getElectriciteit().setIngangsdatum(jdIngangsdatumElectra.getDate());
                }

                //Water aansluiting
                if (this.getPerceel().getWater() == null && this.chkWaterAansluiting.isSelected()) {
                    this.getPerceel().setWater(new Water());
                    this.getPerceel().getWater().setPerceel(this.getPerceel());
                    this.getPerceel().getWater().setIngangsdatum(jdIngangsdatumWater.getDate());
                }
            }
            this.setVisible(false);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAnnuleren;
    private javax.swing.JButton btnOpslaan;
    private javax.swing.JCheckBox chkElectraAansluiting;
    private javax.swing.JCheckBox chkGasaansluiting;
    private javax.swing.JCheckBox chkWaterAansluiting;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private com.toedter.calendar.JDateChooser jdIngangsdatumElectra;
    private com.toedter.calendar.JDateChooser jdIngangsdatumGas;
    private com.toedter.calendar.JDateChooser jdIngangsdatumWater;
    private javax.swing.JPanel pnlElectraAansluiting;
    private javax.swing.JPanel pnlGasAansluiting;
    private javax.swing.JPanel pnlWaterAansluiting;
    private javax.swing.JTextField txtElectraVerbruik;
    private javax.swing.JTextField txtElectraVerbruikNacht;
    private javax.swing.JTextField txtElectraVorigeMeterstand;
    private javax.swing.JTextField txtGasVerbruik;
    private javax.swing.JTextField txtGasVorigeMeterstand;
    private javax.swing.JTextField txtHuisnummer;
    private javax.swing.JTextField txtPlaats;
    private javax.swing.JTextField txtPostcode;
    private javax.swing.JTextField txtStraatnaam;
    // End of variables declaration//GEN-END:variables

    /**
     * Het perceel wat geedit is
     * @return Het perceel
     */
    public Perceel getPerceel() {
        return Perceel;
    }

    /**
     * Geeft aan of het formulier geannuleerd is
     * @return True als geannuleerd, anders false
     */
    public Boolean getCancelled() {
        return _cancelled;
    }
}
